//
//  CYStatusCell.swift
//  CYSinaWB
//
//  Created by mac on 16/2/23.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SnapKit
class CYStatusCell: UITableViewCell {
    
    var bottomViewTopConstraint: Constraint?
    
    var status: CYStatus? {
        didSet {
            statusOriginalView.status = status
            print(status?.imageUrls)
            print(status?.retweeted_status?.text)
//            statusRetweetedView.retweetedStatus = status?.retweeted_status
            self.bottomViewTopConstraint?.uninstall()
            if let re = status?.retweeted_status {
                statusRetweetedView.retweetedStatus = re
                statusBottomView.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomViewTopConstraint = make.top.equalTo(statusRetweetedView.snp_bottom).constraint
                })
                statusRetweetedView.hidden = false
            } else {
                statusBottomView.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomViewTopConstraint = make.top.equalTo(statusOriginalView.snp_bottom).constraint
                })
                statusRetweetedView.hidden = true
            }
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUpUI()
        selectionStyle = .None
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setUpUI() {
        contentView.addSubview(statusOriginalView)
        contentView.addSubview(statusBottomView)
        contentView.addSubview(statusRetweetedView)
        
        statusOriginalView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.top.equalTo(contentView.snp_top)
//            make.height.equalTo(80)
        }
        statusRetweetedView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(statusOriginalView.snp_bottom)
            make.left.equalTo(statusOriginalView.snp_left)
            make.right.equalTo(statusOriginalView.snp_right)
        }
        statusBottomView.snp_makeConstraints { (make) -> Void in
//            make.top.equalTo(statusRetweetedView.snp_bottom)
            self.bottomViewTopConstraint = make.top.equalTo(statusRetweetedView.snp_bottom).constraint
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.height.equalTo(35)
        }
        contentView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.top.equalTo(self.snp_top)
            
            make.bottom.equalTo(statusBottomView.snp_bottom)
        }
        
    }
    
    
    //懒加载视图
    private lazy var statusOriginalView:CYStatusCellOriginalView = CYStatusCellOriginalView()
    
    private lazy var statusRetweetedView: CYStatusRetweetedView = CYStatusRetweetedView()
    
    private lazy var statusBottomView: CYStatusCellBottomView = CYStatusCellBottomView()

}
